﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PixelWarfare
{
    /// <summary>
    /// Returns a number each time you call Next() up to but not 
    /// including a given maximum number in a random order.
    /// It will never return the same number twice.
    /// </summary>
    class RandomOrder
    {
        #region Fields

        private List<int> list = new List<int>();

        #endregion

        #region Constructors

        /// <summary>
        /// Create with a maximum number which the upper non inclusive bound.
        /// </summary>
        /// <param name="max">Upper bound.</param>
        public RandomOrder(int max)
        {
            for(int i = 0;i<max;i++)
            {
                list.Add(i);
            }
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Gets the next random number.
        /// </summary>
        /// <returns>Returns the next random number or -1 if there are no more numbers.</returns>
        public int Next()
        {
            int result;

            if (list.Count > 0)
            {
                result = list.ElementAt(new Random().Next(list.Count));
                list.Remove(result);
            }
            else
            {
                result = -1;
            }

            return result;

        }

        #endregion
    }
}
